package com.cindata

import grails.transaction.Transactional
import org.apache.poi.hwpf.HWPFDocument

@Transactional
class DisputeService
{

    static scope = "singleton"

    def replaceWord(String srcPath, String destPath, Map<String, String> map)
    {
        try
        {
            HWPFDocument document = new HWPFDocument(new FileInputStream(srcPath));
            def range = document.getRange()
            //读取word文本内容
            //替换文本内容
            for (
                Map.Entry entry :
                    map.entrySet())
            {
                range.replaceText(entry.getKey(), entry.getValue());
            }

            FileOutputStream outStream = null;
            outStream = new FileOutputStream(destPath);
            document.write(outStream);
            outStream.close();

        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        return destPath
    }
}
